#pragma once 
#include "Header.h"

namespace Geometry 
{
	class _declspec(dllexport) Triangle
	{
	private:
		Vertex m_vertices[3];
		float m_alpha;
		bool m_decr;
	public:
		Triangle(int x, int y, int width, int height)
		{
			m_decr = true;
			m_alpha = 255.0f;
			m_vertices[0].x = x;
			m_vertices[0].y = y;
			m_vertices[0].color = D3DCOLOR_ARGB((int)m_alpha, 255, 0, 0);

			m_vertices[1].x = x + width;
			m_vertices[1].y = y;
			m_vertices[1].color = D3DCOLOR_ARGB((int)m_alpha, 0, 255, 0);

			m_vertices[2].x = x + width / 2;
			m_vertices[2].y = y + height;
			m_vertices[2].color = D3DCOLOR_ARGB((int)m_alpha, 0, 0, 255);

			m_vertices[0].z = m_vertices[1].z = m_vertices[2].z = 0.0f;
		}

		void DrawTriangle(IDirect3DDevice9* m_device)
		{
			if(m_decr)
			{
				m_alpha -= 0.8f;
				if(m_alpha < 0)
				{
					m_alpha *= -1.0f;
					m_decr = false;
				}
			}
			else
			{
				m_alpha += 0.8f;
				if(m_alpha > 255.0f)
				{
					m_alpha = 510.0f - m_alpha;
					m_decr = true;
				}
			}

			m_vertices[0].color = D3DCOLOR_ARGB((int)m_alpha, 255, 0, 0);
			m_vertices[1].color = D3DCOLOR_ARGB((int)m_alpha, 0, 255, 0);
			m_vertices[2].color = D3DCOLOR_ARGB((int)m_alpha, 0, 0, 255);

			IDirect3DDevice9* dev = m_device;
			dev->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE);
			dev->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 1, m_vertices, sizeof(Vertex));
		}
	};
}